package jc.malpractice;

import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import jc.malpractice.controllers.*;
import jc.malpractice.service.CronService;

import static spark.Spark.*;

public class Main {
    public static void main(String[] args) {
        staticFiles.location("/public");
        port(8080);

        auth();
        EventController.Init();
        MastController.Init();
        UserController.Init();
        DeptController.Init();
        MyeventController.Init();
        AdminController.Init();
        before("/*", (request, response) -> {
            response.header("Access-Control-Allow-Origin", "*");
            response.header("Cache-Control", "no-cache");
        });
//        CronUtil.schedule("*/1 * * * * *", (Task) () ->
////                System.out.println("111")
//                CronService.itmmastSync()
//        );
//        CronUtil.schedule("*/1 * * * *", (Task) () ->
//                CronService.itmmastSync1()
//        );
//        CronUtil.schedule("*/1 * * * *", (Task) () ->
//                CronService.itmmastSync2()
//        );
        CronUtil.schedule("1 1 1 * * *", (Task) () ->
//                System.out.println("111")
                        CronService.itmmastSync()
        );
        CronUtil.schedule("1 1 1 * * *", (Task) () ->
                CronService.itmmastSync1()
        );
        CronUtil.schedule("1 1 1 * * *", (Task) () ->
                CronService.itmmastSync2()
        );
        // 支持秒级别定时任务
//        CronUtil.setMatchSecond(true);
        CronUtil.start();
    }

    public static void auth() {
        before("/board/*", (req, res) -> {

            if (req.session().attribute("username") == null) {
                halt(401);
            }

        });
    }
}

